<?php
namespace app\common\model;

use think\Model;

class AdminCity extends Model
{
    /*
     * 添加
     */
    public function add($data = array()){
        return $this->data($data, true)->isUpdate(false)->save();
    }

    /*
     * 修改
     */
    public function edit($data = array()){
        if (!isset($data['cid']) || empty($data['cid'])) {
            return false;
        }

        return $this->update($data);
    }

    /*
     * 根据ID查找
     */
    public function getInfoById($id){
        $info = $this->where(array('cid' => $id))->find();

        return $info ? $info->toArray() : array();
    }

    /*
     * 分页查找
     */
    public function getList($conditions = array(), $field = null, $size = 10, $url = array(), $order = 'cid desc', $is_page = true){
        $data = array();
        $config['query'] = $url;
        if ($is_page) {
            $result = $this->field($field)->where($conditions)->order($order)->paginate($size,'',$config);

            //返回数据处理
            $list = $result->toArray();
            $data['total'] = $list['total'];
            $data['list'] = $list['data'];
            $data['page'] = $result->render();
        } else {
            $result = $this->field($field)->where($conditions)->order($order)->select();

            //返回数据处理
            $data['list'] = $result->toArray();
//            //返回数据处理
//            $list = $result->toArray();
//            $data['list'] = $list['data'];
        }

        return $data;
    }

}